package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WmNewsMessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/** kafka消费者
 * @author ZQH
 * @version 1.0
 * @date 2023/8/27 21:44
 */
@Slf4j
@Component
public class ArticleIsDownListener {
    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessage(String message){
        if (!StringUtils.isEmpty(message)){
            JSONObject jsonObject = JSON.parseObject(message);
            apArticleConfigService.updateByJSONObject(jsonObject);
        }

    }
}
